GFXEXAMPLES = examples\_gfx.exe \
	examples\_tk.exe \
	examples\keytest.exe \
	examples\bitdump.exe \
	examples\gfx0.exe \
	examples\gfx1.exe \
	examples\gfx2.exe \
	examples\gfx3.exe \
	examples\gfx4.exe 
PUIEXAMPLES = examples\_pui.exe \
	examples\pui0.exe \
	examples\pui1.exe \
	examples\pui2.exe \
	examples\pui3.exe \
	examples\pui4.exe \
	examples\pui5.exe \
	examples\pui6.exe \
	examples\desktop.exe

CFLAGS = -O4 -W -Wall -pedantic 
INCLUDE = include
LIB = 
CDEFINE = 

# --------------------------- Targets ----------------------------------------
.PHONY : all allegro degfx depui mgrx
.PHONY : indent clean zip tgz release version docs cleandocs

all : degfx depui

allegro : CDEFINE += MX_PLATFORM_ALLEGRO
allegro : LIB += alleg
allegro : depui

mgrx : CDEFINE += MX_PLATFORM_MGRX
mgrx : LIB += mgrx
mgrx : depui

svgalib : LIB += vga
svgalib : degfx depui

degfx : $(GFXEXAMPLES)
depui : $(PUIEXAMPLES)

# --------------------------- Rules ------------------------------------------
CDEFINES = $(addprefix -D,$(CDEFINE))
INCLUDES = $(addprefix -I,$(INCLUDE))
LIBS = $(addprefix -l,$(LIB))

%o : %c
	gcc -c $(INCLUDES) $(CDEFINES) $(CFLAGS) $<

%o : %cpp
	gpp -c $(INCLUDES) $(CDEFINES) $(CFLAGS) $<

%exe : %o
	gcc -s -o $@ $(?F) $(LIBS)

#------------------------------ Utility targets ------------------------------
indent:
	find . -name "*.c" -type f -exec indent -kr -l80 -ts4 -lp -bad -fca -npsl -sob -nhnl -bap {} \;
	find . -name "*.h" -type f -exec indent -kr -l80 -ts4 -lp -bad -fca -npsl -sob -nhnl -bap {} \;
	find . -name "*.c~" -type f -exec rm -f {} \;
	find . -name "*.h~" -type f -exec rm -f {} \;

cleandocs:
	-rm -f docs/*.htm
	-rm -f docs/mxdoc.txt
	-rm -f docs/doxygen/*.htm
	-rm -f docs/doxygen/*.gif
	-rm -f docs/doxygen/*.css
	-rm -f docs/doxygen/*.png
	-rm -r docs/global/html
	
clean: cleandocs
	-rm -f depui.zip
	-rm -f *.o
	-rm -f *.dsk
	-rm -f *.obj
	-rm -f *.exe
	-rm -f *.a
	-rm -f examples/*.o 
	-rm -f examples/*.obj
	-rm -f examples/*.exe
	-rm -f examples/*.gdt
	-rm -f examples/*.dat
	-rm -f examples/*.mak
	-rm -f examples/*.lay
	-rm -f examples/*.dsk
	-rm -f examples/*.tds
	-rm -f examples/*.map
	-rm -f examples/rh_opt.*
	-rm -f examples/test
	-rm -f tools/*.exe
	$(MAKE) -Cinclude/depui clean

zip: clean
	-zip -r -9 depui *

tgz: clean
	-tar -cv * >depui33.tar
	-gzip -c <depui33.tar >depui33.tgz
	-rm -f depui33.tar

mxdocs: cleandocs tolower
	-cd docs
	-mxdoc ../include
	-cd ..

docs: cleandocs mxdocs
	-cd include
	-htags -g ../docs/global
	-rm -f gpath
	-rm -f grtags
	-rm -f gsyms
	-rm -f gtags
	-doxygen
	-cd ..

version: 
	-gcc tools\version.c -o version.exe
	-version.exe
	-rm -f version.exe

tolower: 
	-gcc tools\tolower.c -o tolower.exe
	-tolower.exe
	-rm -f tolower.exe

release: 
	$(MAKE) clean
	$(MAKE) tolower
	$(MAKE) version
	$(MAKE) mxdocs
	-zip -r -9 depui33 * -x tools\release
	-ftp -n -s:tools\release ftp.dds.nl
	-rm -f depui33.zip
	$(MAKE) clean

